#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time
from common.readelement import Element
from page_object.webpage import WebPage

askhelp = Element('jzsz/enterprise/ask_help')

class AskHelpPage(WebPage):

    def username(self):
        """用户信息"""
        self.is_click(askhelp['用户信息'])

    def get_askedresume_num(self):
        """获取请求帮助之前的请求数量"""
        self.is_click(askhelp['求帮忙管理'])
        self.is_click(askhelp['邀请人员信息'])
        res = self.is_exists2(askhelp['简历total'])
        if res:
            text = self.find_element(askhelp['简历total']).text  # 获取标记前的简历总量
            resume_num = text[2:-2]
            return resume_num
        else:
            return '0'

    def go_back(self):
        """返回"""
        self.is_click(askhelp['返回'])

    def ask_help(self):
        """
        请TA帮忙
        兼职人员推荐列表展示数量有限，如在第一页中没有’请TA帮忙‘按钮，点击换一批。
        """
        for i in range(3):
            res = self.is_exists2(askhelp['请TA帮忙'])
            if res:
             break
            else:
                self.is_click(askhelp['换一批'])
        self.is_click(askhelp['请TA帮忙'])
        self.is_click(askhelp['确定'])


    def askhelp_success(self,resume_num):
        """验证请TA帮忙成功"""
        self.is_click(askhelp['求帮忙管理'])
        self.is_click(askhelp['邀请人员信息'])
        text = self.find_element(askhelp['简历total']).text   #获取请求帮助后的简历总量
        resume_num2 = text[2:-2]
        if int(resume_num2) == int(resume_num) + 1:
            return True
        else:
            return False

